import {
	myRequest
} from '/utils/request.js';
// 域名
const api = 'https://yiliao.kuxia.top/';
// 登录接口
export const login = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/user/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 注册接口
export const enrolls = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/user/add',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 科室列表
export const lists = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Depart/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 获取openid
// 1. 首先修复api/index.js中的wxLogins接口
export const wxLogins = (data) => {
  return myRequest({
    url: api + 'app/user/getsessionkey',
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    data: data,
  }).then(res => {
    // 确保返回完整的响应数据
    if (res && res.code === 1) {
      return res
    } else {
      throw new Error(res.message || '获取openid失败')
    }
  })
}

// 微信授权
export const licensing = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/user/empower',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 医生列表
export const details = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/doctor/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 医院信息
export const hospital = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Hospital/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 排班列表
export const work = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/scheduling/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 就诊卡列表
export const card = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Visit/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 预约记录添加/编辑
export const registerAdd = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/register/add',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 预约记录列表
export const registerlogs = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/register/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 预约记录删除
export const logsDel = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Register/del',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 预约记录取消
export const logsEdit = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Register/edit',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 门诊缴费记录
export const payLogs = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/pay/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 充值
export const recharge = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/visit/recharge',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 体检检验记录
export const Inspect = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Inspect/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 门诊缴费记录详情
export const Paycord = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Paycord/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 住院日清单
export const billReport = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Report/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 住院日清单明细
export const Reportcord = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Reportcord/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 编辑就诊卡
export const visitEdit = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/visit/edit',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 就诊卡删除
export const visitDel = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/visit/del',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 就诊卡添加
export const cardCreate = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Visit/add',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 医生动态
export const trends = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Trends/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 收藏列表
export const favorites = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'pc/collect/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 添加收藏
export const collectAdd = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'pc/collect/add',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 取消收藏
export const collectDel = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'pc/collect/del',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 信息完善
export const perfection = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/user/message',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 充值列表
export const rechargeable = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/money/index',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};

// 阅读量增加
export const editTrends = (data) => {
	return new Promise((resolve) => {
		console.log(data);
		myRequest({
			url: api + 'app/Trends/edit',
			method: 'POST',
			header: {
				'content-type': 'application/json'
			},
			data: data,
		}).then(res => {
			resolve(res)
		})
	})
};
// 图片上传
export const uploadImage = (imagePath) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: api + 'pc/Fileimg/file',
      filePath: imagePath,
      name: 'file',
      success: (res) => {
        try {
          const result = JSON.parse(res.data);
          if (result.code === 1) {
            uni.showToast({
              title: '上传成功',
              icon: 'success'
            });
            resolve(result.data);
          } else {
            console.error('上传失败:', result.message);
            uni.showToast({
              title: result.message || '上传失败',
              icon: 'none'
            });
            reject(new Error(result.message));
          }
        } catch (parseError) {
          console.error('解析上传结果出错:', parseError);
          uni.showToast({
            title: '解析上传结果出错',
            icon: 'none'
          });
          reject(parseError);
        }
      },
      fail: (err) => {
        console.error('上传失败:', err);
        uni.showToast({
          title: '上传失败',
          icon: 'none'
        });
        reject(err);
      }
    });
  });
};
// 医生列表接口
export const doctorList = (data) => {
  return myRequest({
    url: api + 'app/doctor/index',
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    data: data,
  })
};

// 医生排班接口
export const doctorSchedule = (data) => {
  return myRequest({
    url: api + 'app/scheduling/index',
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    data: data,
  })
};

// 医生详情接口
export const doctorDetails = (data) => {
  return myRequest({
    url: api + 'app/Doctor/details',
    method: 'POST',
    header: {
      'content-type': 'application/json'
    },
    data: data,
  })
};